package cn.acewill.yxd.yunxundian.ui.sign;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import cn.acewill.yxd.yunxundian.BaseActivity;
import cn.acewill.yxd.yunxundian.R;

/**
 * Created by XXX on 2017/8/11.
 */

public class HistoryEvaluationActivity extends BaseActivity{


    private List<Fragment> fragmentList = new ArrayList<>();
    public static int shopid;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.history_evaluation_view);
        initView();
    }
    public void initView(){
        shopid=getIntent().getIntExtra("shopid",0);
        fragmentList.add(new FunctionEvaFragment());
        fragmentList.add(new OperateEvaFragment());
        initToolbar();
        initpage();
    }

    private void initpage(){
        ViewPager mpager = (ViewPager) findViewById(R.id.viewPager);
        TabLayout tabLayout = (TabLayout) findViewById(R.id.myTabs);
        PagerAdapter adapter = new PageAdapter(getSupportFragmentManager());
        mpager.setAdapter(adapter);
        mpager.setOffscreenPageLimit(1);
        mpager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
        tabLayout.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(mpager));
    }
    private void initToolbar(){
        Toolbar toolbar = (Toolbar) findViewById(R.id.myToolBar);
        toolbar.setTitle("");
        toolbar.setNavigationIcon(R.mipmap.back);
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        TextView titleText = (TextView) findViewById(R.id.titleText);
        titleText.setText("签到签出");
    }

    class PageAdapter extends FragmentPagerAdapter{

        public PageAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {

            return fragmentList.get(position);
        }

        @Override
        public int getCount() {
            return fragmentList.size();
        }
    }
}
